package com.jqb.ajaxlab.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;

public class Ajax04 extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		/*Dom4j*/
		SAXReader reader = new SAXReader();
		Document doc = null;
		try {
			doc = reader.read(this.getClass().getClassLoader().getResourceAsStream("User.xml"));
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		response.setHeader("pragma", "no-cache");
		response.setHeader("Cache-control", "no-cache");
		response.setContentType("text/xml;charset=utf-8");
		OutputFormat format = OutputFormat.createPrettyPrint();
		PrintWriter out = response.getWriter();
		XMLWriter writer = new XMLWriter(out, format);
		writer.write(doc);
	}
}
